package ca.etsmtl.log730.projet.view.server;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;

import javax.swing.table.AbstractTableModel;

import org.apache.mina.example.sumup.message.AbstractMessage;

import ca.etsmtl.log730.projet.controller.nmessages.commands.AbstractCommand;

public class EventsTableModel extends AbstractTableModel {
	@Override
	public String getColumnName(int column) {
		if(column == 0) return "TIME";
		else if(column == 1) return "USER";
		else if(column == 3) return "COMMAND";
		return "";
	}

	private Set<Entry<Long, Serializable>> list = new HashSet<Entry<Long, Serializable>>();

	public EventsTableModel() {
		super();
	}
	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public int getRowCount() {
		return list.size();
	}

	@Override
	public Object getValueAt(int y, int x) {
		if(x == 0) return getList().get(y).getKey();
		else if(x == 1) {
//			AbstractCommand am = getList().get(y).getValue();
//			if(am instanceof ClientCommand) {
//				return ((ClientCommand)am).getClientId().toString();
//			}
			return "ROOT";
		}
		else return getList().get(y).getValue().getClass().getSimpleName();
	}

	public ArrayList<Entry<Long, AbstractMessage>> getList() {
		return new ArrayList(list);
	}

	public void setList(Set<Entry<Long, Serializable>> list) {
		this.list = list;
	}

}
